package com.huawei.appgallery.forum.comments.card;

import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.common.media.api.IImagePreviewProtocol;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.ImageInfo;
import com.huawei.appgallery.forum.base.card.bean.Post;
import com.huawei.appgallery.forum.cards.widget.UserInfoTextView;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.forum.user.api.IUserFollow.b;
import com.huawei.appgallery.forum.user.api.IUserHomePageProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.LineImageView;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.blc;
import o.bqx;
import o.bqy;
import o.brd;
import o.bsx;
import o.bsy;
import o.btc;
import o.btu;
import o.bue;
import o.bue.c;
import o.bue.d;
import o.bue.e;
import o.bue.j;
import o.buj;
import o.bwx;
import o.bxc;
import o.cgz;
import o.epv;
import o.CollectCheck;
import o.evx;
import o.fho;
import o.fiu;
import o.fjb;
import o.fjo;
import o.fjq;
import o.fke;
import o.fkg;
import o.ll;

public class ForumCommentDetailHeadCard extends ForumCard {
    private TextView ʻ;
    private buj ʻॱ = null;
    private LineImageView ʼ;
    private UserInfoTextView ʽ;
    private ImageView ˊ;
    private bwx ˊॱ;
    private Context ˋ;
    private boolean ˋˋ;
    private RelativeLayout ˋॱ;
    private long ˋᐝ = 0;
    private int ˌ = 0;
    private int ˍ;
    private LinearLayout ˎ;
    private long ˎˎ;
    private ImageView ˏ;
    private TextView ˏॱ;
    private String ͺ = "";
    private LinearLayout ॱ;
    private RelativeLayout ॱˊ;
    private ForumCommentDetailHeadCardBean ॱˋ;
    private HwButton ॱˎ;
    private TextView ॱॱ;
    private Post ॱᐝ;
    private TextView ᐝ;
    private String ᐝॱ;

    public ForumCommentDetailHeadCard(Context context) {
        super(context);
        this.ˋ = context;
        this.ˊॱ = (bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class);
        if (this.ˋ instanceof buj) {
            this.ʻॱ = (buj) this.ˋ;
        }
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˎ = (LinearLayout) view.findViewById(e.ॱᐝ);
        this.ॱ = (LinearLayout) view.findViewById(e.ॱˎ);
        this.ˋॱ = (RelativeLayout) view.findViewById(e.ˍ);
        this.ˊ = (ImageView) view.findViewById(e.ˊॱ);
        this.ˏ = (ImageView) view.findViewById(e.ॱॱ);
        this.ʼ = (LineImageView) view.findViewById(e.ʼ);
        this.ʽ = (UserInfoTextView) view.findViewById(e.ˏॱ);
        this.ʽ.setShowModeratorStamp(true);
        this.ʽ.setShowHostStamp(true);
        this.ʽ.setHostPriority(this.ʽ.ˎ() + 1);
        this.ʻ = (TextView) view.findViewById(e.ॱˊ);
        this.ᐝ = (TextView) view.findViewById(e.ˋ);
        this.ॱॱ = (TextView) view.findViewById(e.ʻ);
        this.ˏॱ = (TextView) view.findViewById(e.ᐝ);
        this.ॱˊ = (RelativeLayout) view.findViewById(e.ॱ);
        this.ॱˎ = (HwButton) view.findViewById(e.ˏ);
        this.ॱˎ.setOnClickListener(new evx(this) {
            final /* synthetic */ ForumCommentDetailHeadCard ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                this.ˊ.ॱˊ();
            }
        });
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumCommentDetailHeadCardBean) {
            this.ॱˋ = (ForumCommentDetailHeadCardBean) cardBean;
            this.ᐝॱ = this.ॱˋ.ॱ();
            this.ॱᐝ = this.ॱˋ.ʼ();
            int P_ = this.ʻॱ.P_();
            buj o_buj = this.ʻॱ;
            if (P_ == 2) {
                this.ॱˊ.setPadding(0, epv.ˋ(this.ˋ, 8), 0, 0);
            } else {
                this.ॱˊ.setPadding(0, 0, 0, 0);
            }
            this.ˍ = this.ॱᐝ.ॱˊ();
            this.ˎˎ = this.ॱᐝ.ˏ();
            this.ͺ = this.ॱˋ.ʽ().ॱ();
            this.ʽ.setData(this.ॱˋ.ʽ());
            ˊ(this.ʻ, btc.ˏ(this.ˋ, this.ॱᐝ.ˎ()));
            ॱॱ();
            ˎ();
            ᐝ();
            this.ॱ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ForumCommentDetailHeadCard ˋ;

                {
                    this.ˋ = r1;
                }

                public void onClick(View view) {
                    this.ˋ.ʻ();
                }
            });
            this.ˋॱ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ForumCommentDetailHeadCard ˊ;

                {
                    this.ˊ = r1;
                }

                public void onClick(View view) {
                    this.ˊ.ˏ(this.ˊ.ॱˋ.ʽ().ˊ(), this.ˊ.ॱˋ.ॱ());
                }
            });
            this.ˋᐝ = this.ॱᐝ.ʻ();
            ॱ(this.ॱॱ, this.ˋᐝ);
            bsx.ˏ(this.ˋ, this.ˊ, this.ॱˋ.ʽ().ˎ());
            ʽ();
            this.ʽ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ForumCommentDetailHeadCard ˏ;

                {
                    this.ˏ = r1;
                }

                public void onClick(View view) {
                    this.ˏ.ˏ(this.ˏ.ॱˋ.ʽ().ˊ(), this.ˏ.ॱˋ.ॱ());
                }
            });
            this.ˌ = this.ॱˋ.ʽ().ʻॱ();
            ॱ(this.ˌ);
            ʼ();
            ˋॱ();
        }
    }

    private void ˎ() {
        if (this.ॱᐝ.ॱˊ() == 3) {
            this.ˎ.setVisibility(0);
            this.ˏॱ.setText(this.ˋ.getString(j.ˏ));
        } else if (this.ॱᐝ.ॱˊ() == 2) {
            this.ˎ.setVisibility(0);
            this.ˏॱ.setText(this.ˋ.getString(j.ˊ));
        } else {
            this.ˎ.setVisibility(8);
        }
    }

    private void ॱॱ() {
        if (TextUtils.isEmpty(this.ॱᐝ.ॱ())) {
            this.ᐝ.setVisibility(8);
            return;
        }
        this.ᐝ.setVisibility(0);
        this.ᐝ.setText(btu.ॱ(this.ˋ, this.ॱᐝ.ॱ().replace("[br]", "\n"), btu.ˏ()));
        this.ᐝ.setMovementMethod(LinkMovementMethod.getInstance());
    }

    private void ᐝ() {
        if (this.ॱˋ.ᐝ() == 1) {
            this.ˏ.setImageResource(d.ˏ);
            this.ˋˋ = true;
        } else if (this.ॱˋ.ᐝ() == 0) {
            this.ˏ.setImageResource(d.ˋ);
            this.ˋˋ = false;
        }
    }

    private void ʽ() {
        List<ImageInfo> ॱॱ = this.ॱᐝ.ॱॱ();
        String ˏ = ˏ((List) ॱॱ);
        if (TextUtils.isEmpty(ˏ)) {
            this.ʼ.setVisibility(8);
            return;
        }
        this.ʼ.setVisibility(0);
        ॱ(this.ʼ, ˏ, (ImageInfo) ॱॱ.get(0));
        final ArrayList arrayList = new ArrayList();
        for (ImageInfo imageInfo : ॱॱ) {
            blc o_blc = new blc();
            o_blc.ॱ(imageInfo.ˊ());
            o_blc.ॱ(imageInfo.ˎ());
            o_blc.ˋ(imageInfo.ˏ());
            o_blc.ˋ(imageInfo.ˋ());
            arrayList.add(o_blc);
        }
        this.ʼ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumCommentDetailHeadCard ॱ;

            public void onClick(View view) {
                this.ॱ.ˏ(this.ॱ.ˋ, arrayList, 0);
            }
        });
    }

    private void ʼ() {
        if (this.ॱˋ.ʽ().ˊ() == 1 || this.ॱˋ.ʽ().ॱ() == null) {
            ˎ(this.ॱˎ, 8);
        } else {
            ˎ(this.ॱˎ, 0);
        }
    }

    private String ˏ(List<ImageInfo> list) {
        if (CollectCheck.isEmpty((List) list) || list.get(0) == null) {
            return null;
        }
        if (TextUtils.isEmpty(((ImageInfo) list.get(0)).ˋ())) {
            return ((ImageInfo) list.get(0)).ˊ();
        }
        return ((ImageInfo) list.get(0)).ˋ();
    }

    private void ʻ() {
        int i;
        if (this.ˋˋ) {
            i = 1;
        } else {
            i = 0;
        }
        if (this.ˊॱ != null) {
            this.ˊॱ.ˊ(this.ˋ, this.ˍ, 1, this.ˎˎ, i, this.ᐝॱ, this.ॱˋ.ˊ()).ˏ(new fke<bxc>(this) {
                final /* synthetic */ ForumCommentDetailHeadCard ˏ;

                {
                    this.ˏ = r1;
                }

                public /* synthetic */ void ॱ(Object obj) {
                    ˋ((bxc) obj);
                }

                public void ˎ(fkg o_fkg) {
                }

                public void ˋ(bxc o_bxc) {
                    if (o_bxc.ˏ() == 9 && o_bxc.ˎ()) {
                        bqx.ˏ("ForumCommentDetailHeadCard", "AUTHENTION_ACCESS is ok");
                        this.ˏ.ˊॱ();
                    } else if (o_bxc.ˏ() == 0 && o_bxc.ˎ()) {
                        bqx.ˏ("ForumCommentDetailHeadCard", "response is ok");
                    } else if (o_bxc.ˏ() == -1 && !o_bxc.ˎ()) {
                        bqx.ˏ("ForumCommentDetailHeadCard", "response is fail");
                        this.ˏ.ˊॱ();
                    }
                }

                public void ˊ(Exception exception) {
                }

                public void ॱ() {
                }
            });
        }
    }

    private void ˊॱ() {
        if (this.ˋˋ) {
            this.ˏ.setImageResource(d.ˋ);
            this.ˋˋ = false;
            this.ॱˋ.ˎ(0);
            this.ˋᐝ--;
            this.ॱᐝ.ˋ(this.ˋᐝ);
        } else {
            this.ˏ.setImageResource(d.ˏ);
            this.ˋˋ = true;
            this.ॱˋ.ˎ(1);
            this.ˋᐝ++;
            this.ॱᐝ.ˋ(this.ˋᐝ);
        }
        ॱ(this.ॱॱ, this.ˋᐝ);
        ˊ(this.ˋˋ, this.ˋᐝ);
    }

    private void ˏ(int i, String str) {
        if (!TextUtils.isEmpty(this.ͺ)) {
            fjb ˎ = fho.ˏ().ˋ("User").ˎ("UserHomePageActivity");
            IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) ˎ.ˊ();
            iUserHomePageProtocol.setUri("forum|user_detail");
            iUserHomePageProtocol.setUserId(this.ͺ);
            iUserHomePageProtocol.setType(i);
            iUserHomePageProtocol.setDomainId(str);
            fiu.ˊ().ˏ(this.ˋ, ˎ);
        }
    }

    private void ˏ(Context context, ArrayList<blc> arrayList, int i) {
        fjb ˎ = fho.ˏ().ˋ("Media").ˎ("ImagePreview");
        IImagePreviewProtocol iImagePreviewProtocol = (IImagePreviewProtocol) ˎ.ˊ();
        iImagePreviewProtocol.setSavePath(Environment.getExternalStorageDirectory() + "/Pictures/" + this.ˋ.getString(j.ʼ));
        iImagePreviewProtocol.setOffset(i);
        iImagePreviewProtocol.setImageBeans(arrayList);
        fiu.ˊ().ˏ(context, ˎ);
    }

    private void ˊ(boolean z, long j) {
        Intent intent = new Intent("forum.comments.like");
        intent.putExtra("is_like", z);
        intent.putExtra("like_count", j);
        ll.ˏ(this.ˋ).ˋ(intent);
    }

    private void ॱ(ImageView imageView, String str, ImageInfo imageInfo) {
        WindowManager windowManager = (WindowManager) ˉ().getContext().getSystemService("window");
        DisplayMetrics displayMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        int dimension = (int) ((((float) displayMetrics.widthPixels) - ˉ().getContext().getResources().getDimension(c.ˊ)) - ((float) epv.ˋ(ˉ().getContext(), 88)));
        bqx.ˏ("ForumCommentDetailHeadCard", "imgview maxWidth:" + dimension);
        ॱ(imageView, dimension, str, imageInfo.ˎ(), imageInfo.ˏ());
        if (bsx.ˎ(str)) {
            bsx.ˎ(imageView, str);
        } else {
            bsx.ॱ(imageView, str);
        }
    }

    private void ॱ(ImageView imageView, int i, String str, int i2, int i3) {
        Object obj = null;
        if (bsx.ˎ(str)) {
            obj = 1;
        }
        Context context = imageView.getContext();
        int ˎ = ((epv.ˎ(context) - azb.ˏ(context)) - azb.ˊ(context)) - context.getResources().getDimensionPixelSize(c.ˏ);
        LayoutParams layoutParams = imageView.getLayoutParams();
        if (i2 <= 0 || i3 <= 0) {
            layoutParams.width = ˎ;
            layoutParams.height = (int) (0.5f * ((float) ˎ));
        } else {
            float f = ((float) i3) / ((float) i2);
            if (obj != null) {
                layoutParams.width = ˎ;
                layoutParams.height = (int) (((float) ˎ) * f);
            } else if (i2 < ˎ) {
                layoutParams.width = i2;
                layoutParams.height = i3;
            } else {
                layoutParams.width = ˎ;
                layoutParams.height = (int) (((float) ˎ) * f);
            }
        }
        imageView.setLayoutParams(layoutParams);
    }

    private void ॱ(TextView textView, long j) {
        if (j == 0) {
            ˊ(textView, this.ˋ.getString(j.ˊॱ));
        } else {
            ˊ(textView, String.valueOf(j));
        }
    }

    private void ॱˊ() {
        int i = 0;
        if (1 == this.ˌ) {
            i = 1;
        } else if (2 == this.ˌ) {
            i = 1;
        }
        ((IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class)).ॱ(this.ˋ, this.ॱˋ.ʽ(), i).ˏ(new fjq<b>(this) {
            final /* synthetic */ ForumCommentDetailHeadCard ˏ;

            public void onComplete(fjo<b> o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b) {
                if (o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ˊ() && ((b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ()).ˏ() == 0) {
                    this.ˏ.ˌ = ((b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ()).ˋ();
                    this.ˏ.ॱˋ.ʽ().ˎ(this.ˏ.ˌ);
                    this.ˏ.ॱ(this.ˏ.ˌ);
                    this.ˏ.ˋॱ();
                    brd.ॱ.ˋ(bqy.ˋ().ˎ(this.ˏ.ˋ), bqy.ˋ().ˎ(), this.ˏ.ॱˋ.ॱˈ(), "REPLY", i == 0 ? 1 : 0);
                }
            }
        });
    }

    private void ॱ(int i) {
        if (i == 1) {
            this.ˌ = i;
            this.ॱˎ.setText(j.ʻ);
            this.ॱˎ.setTextColor(this.ˋ.getResources().getColor(bue.b.ˊ));
        } else if (i == 2) {
            this.ˌ = i;
            this.ॱˎ.setText(j.ॱॱ);
            this.ॱˎ.setTextColor(this.ˋ.getResources().getColor(bue.b.ˊ));
        } else {
            this.ˌ = i;
            this.ॱˎ.setText(j.ͺ);
            this.ॱˎ.setTextColor(this.ˋ.getResources().getColor(bue.b.ˏ));
        }
    }

    private void ˎ(View view, int i) {
        if (i != view.getVisibility()) {
            view.setVisibility(i);
        }
    }

    private void ˋॱ() {
        this.ॱˎ.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
            final /* synthetic */ ForumCommentDetailHeadCard ˋ;

            {
                this.ˋ = r1;
            }

            public boolean onPreDraw() {
                this.ˋ.ॱˎ.getViewTreeObserver().removeOnPreDrawListener(this);
                this.ˋ.ʽ.setContentWidth((this.ˋ.ͺ() - this.ˋ.ॱˎ.getMeasuredWidth()) - (this.ˋ.ˋ.getResources().getDimensionPixelOffset(c.ॱ) * 2));
                this.ˋ.ʽ.setData(this.ˋ.ॱˋ.ʽ());
                return true;
            }
        });
    }

    private int ͺ() {
        return (azb.ॱ(this.ˋ) - (this.ˋ.getResources().getDimensionPixelOffset(bsy.e.ʿ) * 3)) - this.ˋ.getResources().getDimensionPixelOffset(bsy.e.ˎˎ);
    }
}
